package com.hisan.freeride.common.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * 创建时间 : 2017/9/20
 * 创建人：yangyingqi
 * 公司：嘉善和盛网络有限公司
 * 备注：进度条
 */
public class Progress extends View {

    private int progress=0;



    public Progress(Context context) {
        super(context);
    }

    public Progress(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Progress(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint paint=new Paint();
        paint.setColor(Color.RED);
        paint.setAntiAlias(true);
        paint.setStrokeWidth(2);
        paint.setStyle(Paint.Style.STROKE);
        //xy轴，半径
        canvas.drawCircle(getMeasuredWidth()/2,getMeasuredHeight()/2,100,paint);
        RectF rectF=new RectF(getMeasuredWidth()/2-100,getMeasuredHeight()/2-100,getMeasuredWidth()/2+100,getMeasuredHeight()/2+100);
        paint.setColor(Color.GREEN);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(3);
        canvas.drawArc(rectF,0,360*progress/100,false,paint);
        String name=progress+"%";
        Rect rect=new Rect();
        paint.setTextSize(30);
        paint.getTextBounds(name,0,name.length(),rect);
        paint.setColor(Color.BLACK);
        canvas.drawText(name,getMeasuredWidth()/2-rect.width()/2,getMeasuredHeight()/2+rect.height()/2,paint);
    }

    public void start(int progress){
        this.progress=progress;
        postInvalidate();

    }
    private void Stop(int progress){
        this.progress=progress;
        postInvalidate();
    }


    public  void revomehandler(){
        this.progress=0;

    }
}
